home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr37
/
satsfaxt.zip
/
CCPUTILS.ZIP
/
PARSE.C
< prev
next >
Wrap
Text File
|
1990-01-30
|
5KB
|
114 lines
/*============================================================================*
* *
* PARSE.C *
* *
*----------------------------------------------------------------------------*
* *
* Function to process command line. The available switches are defined *
* in a table in the application code and passed to this function. For *
* each switch found on the command line, the specified variable (in the *
* switch table) is set to the value on the command line. *
* *
* CALL : ParseCommand(int argc, char **argv, STABLE *table, *
* int tablesize); *
* RETURN : New argc/argv with switches removed (only arguments are left); *
* *
* The following source code is intended to assist developers in *
* creating applications which support the DCA/Intel Communicating *
* Applications Specification Version 1.0A. It is provided free of charge *
* and on an as-is basis. THE IMPLIED WARRENTIES OF MERCHANTABILITY AND *
* FITNESS FOR A PARTICULAR PURPOSE ARE SPECIFICALLY EXCLUDED. This source *
* code may be modified, enhanced, copied and distributed with applications *
* that support CAS on a royalty free basis. *
* *
*----------------------------------------------------------------------------*
* *
* HISTORY: *
* - completed 9/14/89. *
* *
*============================================================================*/
#include <stdio.h>
#include <dos.h>
#include "cas.h"
#include "util.h"
#include "parse.h"
#define SWITCHCHAR1 '/'
#define SWITCHCHAR2 '-'
/*---------------------------------------------------------------------------*
* ParseCommand *
*---------------------------------------------------------------------------*
* ParseCommand removes all switches from the command line, entering them *
* into the switch table. argc and argv are adjusted accordingly. *
*---------------------------------------------------------------------------*
* INPUT : argc, argv, the calling program's switch table, and the number *
* of elements in the table. *
* OUTPUT: none *
*---------------------------------------------------------------------------*/
ParseCommand(int argc, char **argv, STABLE *Table, int NElements)
{
int x;
int ccArgc;
char **ccArgv;
char *Switch;
STABLE *T;
ccArgc = 1;
ccArgv = ++argv;
/* Go thru entire command line. */
while(--argc > 0) {
/* Check for switch character. */
if((**argv == SWITCHCHAR1) || (**argv == SWITCHCHAR2)) {
Switch = (*argv) + 1;
while(*Switch) {
x = NElements;
T = Table;
/* Find the switch in the switch table. */
while((x-- >= 0) && (T->Switch != *Switch))
T++;
/* Error if not found, otherwise process it. */
if(x < 0)
CASError(CASBADARG, TRUE, "", 0);
else {
++Switch;
switch(T->Type) {
case INT:
/* Assign integer variable. */
*T->Storage = atoi(Switch);
break;
case BOOL:
/* Assign boolean variable. */
*T->Storage = 1;
break;
case CHAR:
/* Assign character variable. */
*T->Storage = *Switch++;
break;
case STRING:
/* Assign string variable. */
*(char **)T->Storage = Switch++;
break;
}
}
Switch = "";
}
}
else {
/* No switch - then it is an argument (filename etc.). */
*ccArgv++ = *argv;
ccArgc++;
}
argv++;
}
/* Return a new argument count, argv reflects only the arguments - the
switches have been removed. */
return ccArgc;
}